package com.robusta.app.impl;

import com.robusta.app.api.AvailableTemplates;
import com.robusta.app.domain.spreadsheet.templates.Metadata;
import com.robusta.app.persistence.WorkbookMetadataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class LookupAvailableTemplatesFromRepository implements AvailableTemplates {
    private WorkbookMetadataRepository workbookMetadataRepository;

    @Autowired
    public LookupAvailableTemplatesFromRepository(WorkbookMetadataRepository workbookMetadataRepository) {
        this.workbookMetadataRepository = workbookMetadataRepository;
    }

    @Override
    @Transactional(readOnly = true)
    @Cacheable("lookupValues")
    public List<? extends Metadata> lookup() {
        return workbookMetadataRepository.findAll();
    }
}
